package com.achilles.netease;

import android.content.Context;
import android.media.MediaPlayer;
import android.os.Build;
import android.view.WindowManager;

/**
 * Created by AchillesL on 2016-9-15.
 */
public class MusicPlayManager {
    private static MusicPlayManager ourInstance = new MusicPlayManager();
    private MediaPlayer mediaPlayer;
    public static MusicPlayManager getInstance() {
        return ourInstance;
    }
    private MusicStatusChange musicStatusChange;
    private MusicPlayManager() {
    }

    public interface MusicStatusChange {
        public void complete();
    }

    public void play(Context context) {
        if (mediaPlayer == null) {
            mediaPlayer = MediaPlayer.create(context,R.raw.music);
            mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                    if (musicStatusChange != null) {
                        musicStatusChange.complete();
                    }
                }
            });
        }
        mediaPlayer.start();
    }

    public void setMusicStatusChange(MusicStatusChange musicStatusChange) {
        this.musicStatusChange = musicStatusChange;
    }


    public void pause() {
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.pause();
        }
    }

}
